package com.buildings.activity;

import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.bigkoo.pickerview.OptionsPickerView;
import com.buildings.R;
import com.buildings.adapter.FormListAdapter;
import com.buildings.adapter.TaskListAdapter;
import com.buildings.api.Api;
import com.buildings.base.BaseActivity;
import com.buildings.bean.FormListBean;
import com.buildings.bean.FormListResultBean;
import com.buildings.bean.TaskBean;
import com.buildings.http.BaseCallBack;
import com.buildings.http.JsonBuilder;
import com.buildings.http.MyHttpClient;
import com.buildings.util.CustomToast;
import com.buildings.util.DialogUtils;
import com.buildings.util.FormDataUtil;
import com.buildings.util.PickViewUtil;
import com.buildings.util.SPUtil;
import com.google.gson.Gson;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadmoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;

/**
 * 表单列表
 */
public class FormListActivity extends BaseActivity implements View.OnClickListener {

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_right_text)
    TextView tvSelect;
    @BindView(R.id.tv_left_text)
    TextView tvLeftText;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.refreshLayout)
    SmartRefreshLayout refreshLayout;
    @BindView(R.id.tv_status)
    TextView tvStatus;//表单状态
    @BindView(R.id.tv_sort)
    TextView tvSort;//排序

    @BindView(R.id.btn_commit)
    Button btnCommit;
    @BindView(R.id.btn_delete)
    Button btnDelete;
    @BindView(R.id.ll_bottom)
    LinearLayout llBottom;//批量提交布局

    private int pageNum = 1;//当前请求页数
    private int pageSize = 15;
    private int total;//
    private Dialog dialog;

    private FormListAdapter mAdapter;
    private List<FormListBean.FormBean> data;

    private String taskId;
    private String taskName;
    private String status;
    private String type = "4";
    private String buildType = "4";
    private String userId;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_form_list);
        ButterKnife.bind(this);
        initData();
        initView();

    }

    private void initData(){
        taskId = getIntent().getStringExtra("taskId");
        taskName = getIntent().getStringExtra("taskName");
        status = getIntent().getStringExtra("status");//2已完成，   已完成任务下的表单
        userId = (String) SPUtil.get("userId","");
    }

    private void initView(){
        tvTitle.setText("表单");
        tvSelect.setText("选择");
//        tvLeftText.setVisibility(View.VISIBLE);
        tvLeftText.setText("全选");
        refreshLayout.setOnLoadmoreListener(new OnLoadmoreListener() {
            @Override
            public void onLoadmore(RefreshLayout refreshlayout) {
                if(data.size() >= total){
                    CustomToast.showToast(activity,"没有更多的内容");
                    refreshlayout.finishLoadmore();
                }else {
                    getFormList(taskId,type,buildType);
                }
            }
        });
        refreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                pageNum = 1;
                getFormList(taskId,type,buildType);
            }
        });

        showAdapter();
    }

    @OnClick({R.id.iv_back,R.id.tv_status,R.id.tv_sort,R.id.tv_right_text,R.id.btn_commit,R.id.btn_delete,R.id.tv_left_text})
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_status:
                final List<String> statusList = FormDataUtil.getFormListStatus();
                PickViewUtil.showPickerViewOne(activity,"表单状态",statusList,new OptionsPickerView.OnOptionsSelectListener(){
                    @Override
                    public void onOptionsSelect(int options1, int options2, int options3, View v) {
                        String str = statusList.get(options1);
                        // 0未提交  1未审核  2审核未通过 3审核通过   4全部
                        if(TextUtils.equals(FormDataUtil.ALL,str)){
                            type = "4";
                        }else if(TextUtils.equals(FormDataUtil.NO_COMMIT,str)){
                            type = "0";
                        }else if(TextUtils.equals(FormDataUtil.NO_VERIFY,str)){
                            type = "1";
                        }else if(TextUtils.equals(FormDataUtil.VERIFY_FAILED,str)){
                            type = "2";
                        }else if(TextUtils.equals(FormDataUtil.VERIFY_SUCCESS,str)){
                            type = "3";
                        }
                        tvStatus.setText(str);
                        if(dialog != null && !dialog.isShowing()){
                            dialog.show();
                        }
                        setEditStatus(true);
                        pageNum = 1;
                        getFormList(taskId,type,buildType);

                    }
                });
                break;
            case R.id.tv_sort:
                final List<String> sortList = FormDataUtil.getFormListSort();
                PickViewUtil.showPickerViewOne(activity,"建筑类型",sortList,new OptionsPickerView.OnOptionsSelectListener(){
                    @Override
                    public void onOptionsSelect(int options1, int options2, int options3, View v) {
                        String str = sortList.get(options1);
                        //0、城镇住宅1、城镇非住宅，2、农村住房，3、农村公共住宅
                        if(TextUtils.equals(FormDataUtil.ALL,str)){
                            buildType = "4";
                        }else if(TextUtils.equals(FormDataUtil.TOWN_HOUSE,str)){
                            buildType = "0";
                        }else if(TextUtils.equals(FormDataUtil.TOWN_NON_HOUSE,str)){
                            buildType = "1";
                        }else if(TextUtils.equals(FormDataUtil.VILLAGE_HOUSE,str)){
                            buildType = "2";
                        }else if(TextUtils.equals(FormDataUtil.VILLAGE_PUBLIC_HOUSE,str)){
                            buildType = "3";
                        }
                        tvSort.setText(str);
                        if(dialog != null && !dialog.isShowing()){
                            dialog.show();
                        }
                        setEditStatus(true);
                        pageNum = 1;
                        getFormList(taskId,type,buildType);
                    }
                });
                break;
            case R.id.tv_left_text:
                //全选反选
                if(TextUtils.equals("全选",tvLeftText.getText().toString())){
                    tvLeftText.setText("反选");
                    for(FormListBean.FormBean bean : data){
                        bean.setChecked(true);
                    }
                }else {
                    tvLeftText.setText("全选");
                    for(FormListBean.FormBean bean : data){
                        bean.setChecked(false);
                    }
                }
                mAdapter.notifyDataSetChanged();


                break;
            case R.id.tv_right_text:
                setEditStatus(mAdapter.isEdit());
                break;
            case R.id.btn_commit:
                //如果选中的有未完善的提示不能提交
//                for(FormListBean.FormBean bean : data){
//                    if (TextUtils.equals(bean.getIsSaveAll(),"0")){//是否填完0、否  1、是
//
//                    }
//                }
                String ids = "";
                for(FormListBean.FormBean bean : data){
                    if(bean.isChecked()){
                        if(TextUtils.equals(bean.getIsSaveAll(),"0")){//是否填完0、否  1、是
                            //未完善标红提示
//                            mAdapter.setCommitTips(true);
//                            mAdapter.notifyDataSetChanged();
                            CustomToast.showToast(activity,"有未填完的表单");
                            return;
                        }
                        ids = ids + bean.getFwId()+",";
                    }
                }
                if(!TextUtils.isEmpty(ids)){
                    String str = ids.substring(0,ids.length()-1);
                    ids = str;
                }
                Log.e("ids","ids = "+ids);
                if(TextUtils.isEmpty(ids)){
                    CustomToast.showToast(activity,"请选择要提交表单");
                    return;
                }
                final String finalIds = ids;
                DialogUtils.showIOSDialog(activity, "提示", "", "", "", "", null,new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        dialog.show();
                        updateFormList(finalIds);

                    }
                },"确定要提交选择的表单？");

                break;
            case R.id.btn_delete:
                String deleteIds = "";
                for(FormListBean.FormBean bean : data){
                    if(bean.isChecked()){
                        deleteIds = deleteIds + bean.getFwId()+",";
                    }
                }
                if(!TextUtils.isEmpty(deleteIds)){
                    String str = deleteIds.substring(0,deleteIds.length()-1);
                    deleteIds = str;
                }
                Log.e("ids","ids = "+deleteIds);
                if(TextUtils.isEmpty(deleteIds)){
                    CustomToast.showToast(activity,"请选择要删除表单");
                    return;
                }
                final String finalDeleteIds = deleteIds;
                DialogUtils.showIOSDialog(activity, "提示", "", "", "", "", null,new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        dialog.show();
                        deleteFormList(finalDeleteIds);

                    }
                },"确定要删除选择的表单？");

                break;

        }
    }


    private void setEditStatus(boolean flag){
        for(FormListBean.FormBean bean : data){
            bean.setChecked(false);
        }
        if(flag){
            mAdapter.setEdit(false);
            mAdapter.setCommitTips(false);
            tvSelect.setText("选择");
            llBottom.setVisibility(View.GONE);
            tvLeftText.setVisibility(View.GONE);
            refreshLayout.setEnableLoadmore(true);
            refreshLayout.setEnableRefresh(true);
        }else {
            mAdapter.setEdit(true);
            tvSelect.setText("取消");
            mAdapter.setCommitTips(true);
            llBottom.setVisibility(View.VISIBLE);
            tvLeftText.setVisibility(View.VISIBLE);
            tvLeftText.setText("全选");
            refreshLayout.finishLoadmore();
            refreshLayout.finishRefresh();
            refreshLayout.setEnableLoadmore(false);
            refreshLayout.setEnableRefresh(false);
        }
        mAdapter.notifyDataSetChanged();
    }

    private void showAdapter() {
        data = new ArrayList<>();

//        LinearLayoutManager linerLayoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(new LinearLayoutManager(activity));
//        recyclerView.addItemDecoration( new DividerGridItemDecoration(getActivity() ));
        recyclerView.addItemDecoration( new DividerItemDecoration(activity,LinearLayoutManager.VERTICAL));
        mAdapter = new FormListAdapter(activity,data);
        recyclerView.setAdapter(mAdapter);
        mAdapter.setOnItemClickListener(new FormListAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                if(!mAdapter.isEdit()){
                    FormListBean.FormBean bean = data.get(position);
//                    String type = bean.getSpType();//表单状态  0未提交  1未审核  2审核未通过 3审核通过
//                    if(TextUtils.equals("0",type)){
                        startForm(position,bean);
//                    }
                }
            }
            @Override
            public void onItemLongClick(View view, final int position) {

            }

            @Override
            public void onSubmit(View view, int position) {
                final FormListBean.FormBean bean = data.get(position);
                DialogUtils.showIOSDialog(activity, "提示", "", "", "", "", null,new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        dialog.show();
                        updateFormList(bean.getFwId());

                    }
                },"确定要提交当前表单？");


            }

            @Override
            public void onEdit(View view, int position) {
                FormListBean.FormBean bean = data.get(position);
                startForm(position,bean);
            }

            @Override
            public void onDelete(View view, final int position) {
                DialogUtils.showIOSDialog(activity, "提示", "", "", "", "", null,new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        FormListBean.FormBean bean = data.get(position);
                        dialog.show();
                        deleteFormList(bean.getFwId());

                    }
                },"确定要删除该表单？");


            }


        });
        dialog = DialogUtils.showRefreshDialog(activity);
        getFormList(taskId,type,buildType);

//        String result = "{\"code\":200,\"data\":{\"total\":100,\"rows\":[{\"fwId\":\"2bdb68024dad4942b42fb69d8c61466c\",\"taskId\":\"2\",\"bulidingLongitude\":\"112.08184\",\"bulidingLatitude\":\"37.24135\",\"buildingName\":\"农村公共建筑\",\"formId\":\"cd13ff862e6d41eaa72d653be0485b14\",\"createUserId\":null,\"createTime\":\"2020-05-19T16:00:00.000+0000\",\"bulidingType\":\"3\",\"spType\":\"0\",\"isValid\":\"1\",\"isSaveAll\":\"0\",\"taskName\":\"31\",\"collecPerson\":null},{\"fwId\":\"473699fe57e04dfc8d3c9cb1c0b40aba\",\"taskId\":\"2\",\"bulidingLongitude\":\"112.08078\",\"bulidingLatitude\":\"37.24162\",\"buildingName\":\"城镇住宅\",\"formId\":\"d3d8099452de4435ab2107d09052fc3a\",\"createUserId\":null,\"createTime\":\"2020-05-19T16:00:00.000+0000\",\"bulidingType\":\"0\",\"spType\":\"0\",\"isValid\":\"1\",\"isSaveAll\":\"0\",\"taskName\":\"31\",\"collecPerson\":null},{\"fwId\":\"63bd86dd789245928ad264fa70a05bd8\",\"taskId\":\"2\",\"bulidingLongitude\":\"112.08073\",\"bulidingLatitude\":\"37.24104\",\"buildingName\":\"农村住宅\",\"formId\":\"cfff85904d534aecb865a22620dd61d0\",\"createUserId\":null,\"createTime\":\"2020-05-19T16:00:00.000+0000\",\"bulidingType\":\"2\",\"spType\":\"1\",\"isValid\":\"1\",\"isSaveAll\":\"1\",\"taskName\":\"31\",\"collecPerson\":null},{\"fwId\":\"789e724a8b6243c694cbc84d271178b5\",\"taskId\":\"2\",\"bulidingLongitude\":\"112.08192\",\"bulidingLatitude\":\"37.24197\",\"buildingName\":\"城镇非住宅\",\"formId\":\"69a0d8fdfae24d03b1f4570d793c87a9\",\"createUserId\":null,\"createTime\":\"2020-05-19T16:00:00.000+0000\",\"bulidingType\":\"1\",\"spType\":\"0\",\"isValid\":\"1\",\"isSaveAll\":\"1\",\"taskName\":\"31\",\"collecPerson\":null},{\"fwId\":\"63bd86dd789245928ad264fa70a05bd8\",\"taskId\":\"2\",\"bulidingLongitude\":\"112.08073\",\"bulidingLatitude\":\"37.24104\",\"buildingName\":\"农村住宅\",\"formId\":\"cfff85904d534aecb865a22620dd61d0\",\"createUserId\":null,\"createTime\":\"2020-05-19T16:00:00.000+0000\",\"bulidingType\":\"2\",\"spType\":\"1\",\"isValid\":\"1\",\"isSaveAll\":\"1\",\"taskName\":\"31\",\"collecPerson\":null},{\"fwId\":\"63bd86dd789245928ad264fa70a05bd8\",\"taskId\":\"2\",\"bulidingLongitude\":\"112.08073\",\"bulidingLatitude\":\"37.24104\",\"buildingName\":\"农村住宅\",\"formId\":\"cfff85904d534aecb865a22620dd61d0\",\"createUserId\":null,\"createTime\":\"2020-05-19T16:00:00.000+0000\",\"bulidingType\":\"2\",\"spType\":\"1\",\"isValid\":\"1\",\"isSaveAll\":\"1\",\"taskName\":\"31\",\"collecPerson\":null},{\"fwId\":\"63bd86dd789245928ad264fa70a05bd8\",\"taskId\":\"2\",\"bulidingLongitude\":\"112.08073\",\"bulidingLatitude\":\"37.24104\",\"buildingName\":\"农村住宅\",\"formId\":\"cfff85904d534aecb865a22620dd61d0\",\"createUserId\":null,\"createTime\":\"2020-05-19T16:00:00.000+0000\",\"bulidingType\":\"2\",\"spType\":\"1\",\"isValid\":\"1\",\"isSaveAll\":\"1\",\"taskName\":\"31\",\"collecPerson\":null},{\"fwId\":\"63bd86dd789245928ad264fa70a05bd8\",\"taskId\":\"2\",\"bulidingLongitude\":\"112.08073\",\"bulidingLatitude\":\"37.24104\",\"buildingName\":\"农村住宅\",\"formId\":\"cfff85904d534aecb865a22620dd61d0\",\"createUserId\":null,\"createTime\":\"2020-05-19T16:00:00.000+0000\",\"bulidingType\":\"2\",\"spType\":\"1\",\"isValid\":\"1\",\"isSaveAll\":\"1\",\"taskName\":\"31\",\"collecPerson\":null},{\"fwId\":\"63bd86dd789245928ad264fa70a05bd8\",\"taskId\":\"2\",\"bulidingLongitude\":\"112.08073\",\"bulidingLatitude\":\"37.24104\",\"buildingName\":\"农村住宅\",\"formId\":\"cfff85904d534aecb865a22620dd61d0\",\"createUserId\":null,\"createTime\":\"2020-05-19T16:00:00.000+0000\",\"bulidingType\":\"2\",\"spType\":\"1\",\"isValid\":\"1\",\"isSaveAll\":\"1\",\"taskName\":\"31\",\"collecPerson\":null},{\"fwId\":\"63bd86dd789245928ad264fa70a05bd8\",\"taskId\":\"2\",\"bulidingLongitude\":\"112.08073\",\"bulidingLatitude\":\"37.24104\",\"buildingName\":\"农村住宅\",\"formId\":\"cfff85904d534aecb865a22620dd61d0\",\"createUserId\":null,\"createTime\":\"2020-05-19T16:00:00.000+0000\",\"bulidingType\":\"2\",\"spType\":\"1\",\"isValid\":\"1\",\"isSaveAll\":\"1\",\"taskName\":\"31\",\"collecPerson\":null},{\"fwId\":\"63bd86dd789245928ad264fa70a05bd8\",\"taskId\":\"2\",\"bulidingLongitude\":\"112.08073\",\"bulidingLatitude\":\"37.24104\",\"buildingName\":\"农村住宅\",\"formId\":\"cfff85904d534aecb865a22620dd61d0\",\"createUserId\":null,\"createTime\":\"2020-05-19T16:00:00.000+0000\",\"bulidingType\":\"2\",\"spType\":\"1\",\"isValid\":\"1\",\"isSaveAll\":\"1\",\"taskName\":\"31\",\"collecPerson\":null},{\"fwId\":\"63bd86dd789245928ad264fa70a05bd8\",\"taskId\":\"2\",\"bulidingLongitude\":\"112.08073\",\"bulidingLatitude\":\"37.24104\",\"buildingName\":\"农村住宅\",\"formId\":\"cfff85904d534aecb865a22620dd61d0\",\"createUserId\":null,\"createTime\":\"2020-05-19T16:00:00.000+0000\",\"bulidingType\":\"2\",\"spType\":\"1\",\"isValid\":\"1\",\"isSaveAll\":\"1\",\"taskName\":\"31\",\"collecPerson\":null},{\"fwId\":\"63bd86dd789245928ad264fa70a05bd8\",\"taskId\":\"2\",\"bulidingLongitude\":\"112.08073\",\"bulidingLatitude\":\"37.24104\",\"buildingName\":\"农村住宅\",\"formId\":\"cfff85904d534aecb865a22620dd61d0\",\"createUserId\":null,\"createTime\":\"2020-05-19T16:00:00.000+0000\",\"bulidingType\":\"2\",\"spType\":\"1\",\"isValid\":\"1\",\"isSaveAll\":\"1\",\"taskName\":\"31\",\"collecPerson\":null}],\"message\":\"查询成功\"},\"message\":null}";
//        Gson gson = new Gson();
//        FormListResultBean resultBean = gson.fromJson(result,FormListResultBean.class);
//        data.addAll(resultBean.getData().getRows());
//        update();



        if(TextUtils.equals("2",status)){
            tvSelect.setVisibility(View.INVISIBLE);
            mAdapter.setStatus(status);
        }

    }

    private void startForm(int position,FormListBean.FormBean bean){
        //0、城镇住宅1、城镇非住宅，2、农村住房，3、农村公共住宅
        Intent intent = null;
        if(TextUtils.equals(bean.getBulidingType(),"0")){
            intent = new Intent(activity,TownHouseFormActivity.class);

        }else if(TextUtils.equals(bean.getBulidingType(),"1")){
            intent = new Intent(activity,TownNonHouseFormActivity.class);

        }else if(TextUtils.equals(bean.getBulidingType(),"2")){
            intent = new Intent(activity,VillageHouseFormActivity.class);

        }else {
            intent = new Intent(activity,VillagePublicFormActivity.class);

        }
        String type = bean.getSpType();//表单状态  0未提交  1未审核  2审核未通过 3审核通过
        if(TextUtils.equals("0",type) || TextUtils.equals("2",type)){
            //未提交  审核未通过   可以编辑
            intent.putExtra("isEdit",true);
        }else {
            //不可以编辑，只能查看
            intent.putExtra("isEdit",false);
        }

        if(TextUtils.equals("2",status)){
            //任务已完成，表单都不可编辑
            intent.putExtra("isEdit",false);
        }

//        intent.putExtra("isFirst",false);
        intent.putExtra("formId",bean.getFormId());
        intent.putExtra("taskName",taskName);
        intent.putExtra("taskId",taskId);
        intent.putExtra("buildType",bean.getBulidingType());
        intent.putExtra("lng",bean.getBulidingLongitude());
        intent.putExtra("lat",bean.getBulidingLatitude());
        startActivityForResult(intent,1000);
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode == 1000 && resultCode == RESULT_OK){
            setEditStatus(true);
            pageNum = 1;
            dialog.show();
            getFormList(taskId,type,buildType);
        }
    }

    private void update(){
        mAdapter.update(data);
    }

    private void getFormList(String taskId,String type,String buildType) {
       String url = Api.FORM_LIST+"?taskId="+taskId+"&type="+type+"&buildType="+buildType+"&curtPage="+pageNum+"&pageSize="+pageSize;

        MyHttpClient
                .newBuilder()
                .get()
                .url(url)
//                .addParam(jsonBuilder.toJsonString())
                .build()
                .enqueue(new BaseCallBack<FormListResultBean>() {
                    @Override
                    public void onSuccess(FormListResultBean bean) {
                        super.onSuccess(bean);
                        refreshLayout.finishLoadmore();
                        refreshLayout.finishRefresh();
                        if(bean.getCode() == 200){
                            if(pageNum == 1){
                                //第一页
                                data.clear();
                            }
                            pageNum++;
                            total = bean.getData().getTotal();
                            List<FormListBean.FormBean> result = bean.getData().getRows();
                            data.addAll(result);
                            update();
                        }else {
                            CustomToast.showToast(activity,"获取失败");
                        }
                        if (dialog != null)
                            dialog.dismiss();
                    }

                    @Override
                    public void onFailure(Call call, IOException e) {
                        super.onFailure(call, e);
                        refreshLayout.finishLoadmore();
                        refreshLayout.finishRefresh();
                        CustomToast.showToast(activity,"网络异常");
                        if (dialog != null)
                            dialog.dismiss();
                    }

                    @Override
                    public void onError(int code) {
                        super.onError(code);
                        refreshLayout.finishLoadmore();
                        refreshLayout.finishRefresh();
                        CustomToast.showToast(activity,"网络异常");
                        if (dialog != null)
                            dialog.dismiss();
                    }
                });

    }

    /**
     * 批量提交表单   {type}/subAll/{ids}
     */
    private void updateFormList(String ids) {
        String url = Api.UPDATE_FORM+"1/subAll/"+ids;

        MyHttpClient
                .newBuilder()
                .post()
                .url(url)
//                .addParam(jsonBuilder.toJsonString())
                .build()
                .enqueue(new BaseCallBack<FormListResultBean>() {
                    @Override
                    public void onSuccess(FormListResultBean bean) {
                        super.onSuccess(bean);
                        if(bean != null && bean.getCode() == 200){
                            setEditStatus(true);
                            pageNum = 1;
                            getFormList(taskId,type,buildType);
                        }else {
                            CustomToast.showToast(activity,"提交失败");
                        }
                        if (dialog != null)
                            dialog.dismiss();
                    }

                    @Override
                    public void onFailure(Call call, IOException e) {
                        super.onFailure(call, e);
                        CustomToast.showToast(activity,"网络异常");
                        if (dialog != null)
                            dialog.dismiss();
                    }

                    @Override
                    public void onError(int code) {
                        super.onError(code);
                        CustomToast.showToast(activity,"网络异常");
                        if (dialog != null)
                            dialog.dismiss();
                    }
                });

    }

    /**
     * 批量删除表单   /{ids}/deletAll
     */
    private void deleteFormList(String ids) {
        String url = Api.DELETE_FORM+ids+"/deletAll";

        MyHttpClient
                .newBuilder()
                .post()
                .url(url)
//                .addParam(jsonBuilder.toJsonString())
                .build()
                .enqueue(new BaseCallBack<FormListResultBean>() {
                    @Override
                    public void onSuccess(FormListResultBean bean) {
                        super.onSuccess(bean);
                        if(bean != null && bean.getCode() == 200){
                            setEditStatus(true);
                            pageNum = 1;
                            getFormList(taskId,type,buildType);
                        }else {
                            CustomToast.showToast(activity,"提交失败");
                        }
                        if (dialog != null)
                            dialog.dismiss();
                    }

                    @Override
                    public void onFailure(Call call, IOException e) {
                        super.onFailure(call, e);
                        CustomToast.showToast(activity,"网络异常");
                        if (dialog != null)
                            dialog.dismiss();
                    }

                    @Override
                    public void onError(int code) {
                        super.onError(code);
                        CustomToast.showToast(activity,"网络异常");
                        if (dialog != null)
                            dialog.dismiss();
                    }
                });

    }


}
